package it.polimi.travelDreamEJB.basicproductmanagement;

import it.polimi.travelDreamEJB.basicproductmanagement.dto.FlightDTO;
import it.polimi.travelDreamEJB.travelpacketmanagement.PersonalizedPacket;

import java.io.Serializable;

import javax.persistence.*;

import java.util.Date;
import java.util.List;

/**
 * The persistent class for the flight database table.
 * 
 */
@Entity
@Table(name = "flight")
@NamedQueries({
		@NamedQuery(name = "Flight.findAll", query = "SELECT f FROM Flight f"),
		@NamedQuery(name = "Flight.find", query = "SELECT f FROM Flight f WHERE f.airline LIKE :airline AND f.departure LIKE :departure AND f.departureAirport LIKE :departure_airport AND f.destination LIKE :destination AND f.destinationAirport LIKE :destination_airport AND f.flightDate <= :toFlightDate AND f.flightDate >= :fromFlightDate AND f.price <= :maxPrice AND f.price >= :minPrice"),
		@NamedQuery(name = "Flight.destinationCities", query = "SELECT f FROM Flight f GROUP BY f.destination"),
		@NamedQuery(name = "Flight.departureCities", query = "SELECT f FROM Flight f GROUP BY f.departure") })
public class Flight implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id_flight")
	private int idFlight;

	private String airline;

	private String departure;

	@Column(name = "departure_airport")
	private String departureAirport;

	private String destination;

	@Column(name = "destination_airport")
	private String destinationAirport;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "flight_date")
	private Date flightDate;

	private int price;

	// bi-directional many-to-one association to PersonalizedPacket
	@OneToMany(mappedBy = "departureFlight", cascade=CascadeType.ALL)
	private List<PersonalizedPacket> departureFlightOfPersonalizedPacket;

	// bi-directional many-to-one association to PersonalizedPacket
	@OneToMany(mappedBy = "returnFlight", cascade=CascadeType.ALL)
	private List<PersonalizedPacket> returnFlightOfPersonalizedPacket;

	public Flight() {
	}

	public Flight(FlightDTO flight) {
		this.idFlight = flight.getId();
		this.airline = flight.getAirline();
		this.departureAirport = flight.getDeparture_airport();
		this.departure = flight.getDeparture();
		this.destinationAirport = flight.getDestination_airport();
		this.destination = flight.getDestination();
		this.flightDate = flight.getFlightDate();
		this.price = flight.getPrice();
	}

	public List<PersonalizedPacket> getDepartureFlightOfPersonalizedPacket() {
		return departureFlightOfPersonalizedPacket;
	}

	public void setDepartureFlightOfPersonalizedPacket(
			List<PersonalizedPacket> departureFlightOfPersonalizedPacket) {
		this.departureFlightOfPersonalizedPacket = departureFlightOfPersonalizedPacket;
	}

	public List<PersonalizedPacket> getReturnFlightOfPersonalizedPacket() {
		return returnFlightOfPersonalizedPacket;
	}

	public void setReturnFlightOfPersonalizedPacket(
			List<PersonalizedPacket> returnFlightOfPersonalizedPacket) {
		this.returnFlightOfPersonalizedPacket = returnFlightOfPersonalizedPacket;
	}

	public int getIdFlight() {
		return this.idFlight;
	}

	public void setIdFlight(int idFlight) {
		this.idFlight = idFlight;
	}

	public String getAirline() {
		return this.airline;
	}

	public void setAirline(String airline) {
		this.airline = airline;
	}

	public String getDeparture() {
		return this.departure;
	}

	public void setDeparture(String departure) {
		this.departure = departure;
	}

	public String getDepartureAirport() {
		return this.departureAirport;
	}

	public void setDepartureAirport(String departureAirport) {
		this.departureAirport = departureAirport;
	}

	public String getDestination() {
		return this.destination;
	}

	public void setDestination(String destination) {
		this.destination = destination;
	}

	public String getDestinationAirport() {
		return this.destinationAirport;
	}

	public void setDestinationAirport(String destinationAirport) {
		this.destinationAirport = destinationAirport;
	}

	public Date getFlightDate() {
		return this.flightDate;
	}

	public void setFlightDate(Date flightDate) {
		this.flightDate = flightDate;
	}

	public int getPrice() {
		return this.price;
	}

	public void setPrice(int price) {
		this.price = price;
	}

}